package chapter1.date.task;
/*
7：学士后月考是每月的第一个周六，输出今年的月考时间
 */

import java.text.SimpleDateFormat;
import java.util.*;

public class Task7 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat a = new SimpleDateFormat("yyyy/MM/dd hh时");
        System.out.print("请输入年份：");
        String year;
        while (!(year = input.next()).matches("\\d{4}"))
            System.out.println("输入错误，请重新输入：");
        calendar.set(Calendar.YEAR, Integer.parseInt(year));
        calendar.set(Calendar.MONTH, 0);
        calendar.set(Calendar.HOUR, 8);
        System.out.println("考试时间为：");

        while (calendar.get(Calendar.YEAR) <= Integer.parseInt(year)) {
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            int weekDay = calendar.get(Calendar.DAY_OF_WEEK);  //这个月第一天是星期几
            if (weekDay != 7)  //这个月第一天不是周六
                calendar.add(Calendar.DAY_OF_MONTH, 7 - weekDay); 
            System.out.println(a.format(calendar.getTime()));
            calendar.add(Calendar.MONTH, 1);
        }


    }
}

